package com.jiefutong.zyt.http;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/12/8.
 */
public class XCRRestProvider {
    private static XCRRestProvider sInstance = null;
    private HttpProvider mXCRHttpClient;
    private Retrofit mRetrofit;
    //private Context mContext;

    public static XCRRestProvider getInstance() {
        if (sInstance == null) {
            sInstance = new XCRRestProvider();
        }
        return sInstance;
    }

    private XCRRestProvider() {
    }

    /* public XCRRestProvider init(Context context, String baseUrl, String credentialUrl) {
         mContext = context;
         mXCRHttpClient = HttpProvider.getInstance();
         mRetrofit = new Retrofit.Builder()
                 .client(mXCRHttpClient.getOkHttpClient())
                 .baseUrl(baseUrl)
                 .addConverterFactory(GsonConverterFactory.create())
                 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                 .build();
         return this;
     }*/
    public XCRRestProvider init(String baseUrl) {
        //   mContext = context;
        mXCRHttpClient = HttpProvider.getInstance();
        mRetrofit = new Retrofit.Builder()
                .client(mXCRHttpClient.getOkHttpClient())
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return this;
    }

    public <T> T create(final Class<T> service) {
        return mRetrofit.create(service);
    }

    public OkHttpClient getOkHttpClient() {
        return mXCRHttpClient.getOkHttpClient();
    }
}
